package cn.bugstack.test.domain;


import cn.bugstack.domain.strategy.service.armory.IStrategyArmory;
import cn.bugstack.domain.strategy.service.armory.IStrategyDispatch;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class StrategyArmoryTest {
   
    //负责装配策略概率
    @Resource
    private IStrategyArmory strategyArmory;

    //负责抽奖
    @Resource
    private IStrategyDispatch strategyDispatch;


    /**
     * 根据 策略id 来 进行策略概率装配
     */
    @Before
    public void test_assembleLotteryStrategy(){
        strategyArmory.assembleLotteryStrategy(100001L);
        log.info("装配抽奖策略成功~~");
    }

    /**
     * 只根据 策略 id 来进行 抽奖
     */
    @Test
    public void test_getRandomAwardId(){
        //抽三次奖
        log.info("第一次抽奖：" + strategyDispatch.getRandomAwardId(100001L));
//        log.info("第二次抽奖：" + strategyArmory.getRandomAwardId(100001L));
//        log.info("第三次抽奖：" + strategyArmory.getRandomAwardId(100001L));

    }

    /**
     * 根据 策略 id 和 权重策略值 ruleWeightValues 来进行 抽奖
     */
    @Test
    public void test_getRandomAwardIdAndRuleWeightValues(){
        //抽三次奖
        log.info("测试结果：{} - 4000 策略配置", strategyDispatch.getRandomAwardId(100001L, "4000:102,103,104,105"));
        log.info("测试结果：{} - 5000 策略配置", strategyDispatch.getRandomAwardId(100001L, "5000:102,103,104,105,106,107"));
        log.info("测试结果：{} - 6000 策略配置", strategyDispatch.getRandomAwardId(100001L, "6000:102,103,104,105,106,107,108,109"));

    }

}
